import { Channels } from '/imports/models/Channels';

Template.exploreContent.onCreated(function() {
  this.infiniteScroll({
    query: {
      'type.name': Router.current().params.name
    },
    publication: 'Explore.Channels.ByTypes',
    countPublication: 'Explore.Channels.ByTypes.Counts',
    perPage: 20
  });
});

Template.exploreContent.helpers({
  results: function() {
    const typeName = Router.current().params.name;
    const selector = {};
    if (typeName != 'all') {
      selector['type.name'] = typeName;
    }
    return Channels.find(selector, { 
      limit: Template.instance().getLimit(),
      sort: { createdAt: -1 } 
    });
  },
  loading: function() {
    return !Template.instance().resultSub.ready();
  }
});